Command and Data modes (modem)

Command and Data modes refer to the two modes in which a computer modem may operate. These modes are defined in the Hayes command set, which is the de-facto standard for all modems. These modes exist because there is only one channel of communication between the modem and the computer, which must carry both the computer's commands to the modem, as well as the data that the modem is enlisted to transmit to the remote party over the telephone line.

When a modem is in command mode, any characters sent to it are interpreted as commands for the modem to execute, per the Hayes command set. A command is preceded by the letters 'AT', which stand for 'Attention'. For example, if a modem receives 'ATDT5551212' while in the command mode, it interprets that as an instruction to dial the numbers 5551212 on the telephone, using touch-tone dialing. While in command mode, the modem may send responses back to the computer indicating the outcome of the command. For example, the modem may respond with the word "BUSY" in response to the ATDT command, if it hears a busy signal after dialing and is configured to listen for busy signals.

Any communication in command mode (in both directions) is terminated by a carriage return.

When a modem is in data mode, any characters sent to the modem are intended to be transmitted to the remote party. The modem enters data mode immediately after it makes a connection. For example, if ATDT5551212 resulted in a phone call that was answered by another computer modem, the modem would report the word "CONNECT" and then switch to data mode. Any further characters received over the serial link are deemed to be from the remote party, and any characters sent are transmitted to the remote party.

When a voice-capable modem is in "voice data" mode, any data sent to the modem is interpreted as audio data to be played over the phone line, rather than character bytes to be transmitted digitally to the other party.

Switching between modes

Modems always start out in command mode when powered up. Here are the ways a modem can switch to data mode:

Modems switch back into command mode from data mode for the following reasons:

Practical contemporary use

Today, most modems are configured with the characters "&C1&D2" in the initialization string, or otherwise behave this way by default. This causes the following behavior:

Data Link Escape (DLE) messages

For normal dial-up data communications, modems enter data mode only once - starting when the session connects, and ending when the session disconnects. However, when modems are used for fax and voice (audio) communication, they rapidly switch between command and data modes several times during a call. This is because the role of the modem changes more frequently - rather than simply handing bytes from point A to point B, it is either negotiating parameters and pages with a fax machine, or switching between recording, pausing, and playback audio modes.

In fax and voice data modes, sometimes events occur that the modem wishes to signal to the computer regardless of whether it's in command or data mode. An example of such an event is a caller pressing a touch-tone key in voice mode. Other common DLE messages are notifications from the modem that data was lost because the computer is sending data either too slow or too fast, or that the modem hears an unexpected dial-tone on the line (meaning the caller probably hung up), or that the extension handset was picked up or hung up.

This type of event is signalled with a DLE message, which is a single-character message preceded by a Data Link Escape code. DLE is a character sent from the modem to the computer whose definition is unrelated to either command or data mode, and which uses a specific ASCII code (0x10) which never occurs in any AT commands or responses, so that it can be isolated from the command/response stream on that merit alone. In these modes, whenever a DLE (0x10) is sent, the character following it has a special non-command and non-data meaning. For example, a DLE followed by the number 2 means the caller pressed the number 2 on his telephone keypad. This could happen in either command or data mode so long as the phone line is in use by the modem and someone is on the other end of the line.

Of course, the DLE character could legitimately appear in fax or audio data. For this, a special exception is made: two DLE's in a row means "interpret one literal byte 0x10".

DLE is also used lightly in communication from the computer to the modem. One specific DLE event signals the end of a fax page, or the end of an audio file. That event returns the modem back into command mode. Unlike in standard dial-up data mode, dropping DTR isn't an appropriate way to resume command mode since a hangup is not desired, and an escape code with mandatory pauses isn't suitable either. Because of this, literal 0x10 bytes in data are doubled from the computer to the modem as well.

DLE is never used in standard modem-to-modem data modes such as the one used for dial-up Internet access, at least not by the modem itself. In these modes, DLE is passed over the line just like any other character. DLE (and DLE-escaped messages) are only used by a modem for fax and voice applications, when it is specifically placed in a fax or voice mode.